
<template src="./tpl.html"></template>

<script>
import { CONSENT_GET_USER ,GET_SSO_LOGIN} from "_SERVICES/api";
import md5 from "md5";
import {initRouter} from 'UTILS/util.js'

export default {
  name: "login",
  data() {
    return {
      ruleForm: {
        user_name: "",
        user_pwd: "",
      },
      rules: {
        user_name: [
          { required: true, message: "请输入写用户名", trigger: "blur" },
        ],
        user_pwd: [{ required: true, message: "请输入密码", trigger: "blur" }],
  
      },

    
      bg: {
        backgroundImage: "url(" + require("../../../CST/assets/zsqy.jpg") + ")",
        backgroundSize: "cover",
        backgroundColor: "#0a5897",
        backgroundRepeat: "no-repeat",
        backgroundPosition: "center",
      },
      loading: false,
      activeName:"1"
    };
  },
  created() {
    // if(process.env.VUE_APP_build_type == 'development') {
    // localStorage.setItem(
    //   "cst_userInfo",
    //   JSON.stringify({
    //     YHZH:'ZLY02',
    //     ZKID:46,
    //     YHID:27639,
    //     YHMC:"孙贤",
    //     ZKMC:"内镜中心"
    //   })
    // );
    // }

    if(this.$route.query.sso_token){
      this.getSSOLogin(this.$route.query.sso_token);
    }
   
  },
  methods: {
    getSSOLogin(sso_token) {
      GET_SSO_LOGIN({
        sso_token: sso_token
      }).then((res)=>{
        this.ruleForm.user_name=res.data.YHZH;
        this.ruleForm.user_pwd=res.data.YHMM;
        this.getLogin(1);
      });
    },
   
    upperUsername() {
      this.ruleForm.user_name = this.ruleForm.user_name.toUpperCase()
    },
    getLogin(type) {
      let obj = {
        user_name: this.ruleForm.user_name,
        user_pwd: md5(this.ruleForm.user_pwd),
      };
      if(type==1){
        obj.user_pwd = this.ruleForm.user_pwd;
      }

      this.loading = true;
      CONSENT_GET_USER(obj)
        .then((res) => {
          this.loading = false;
          if (res.data && res.data.YHID) {
            // res.data.ROLE_ID=1
            if(!res.data.YMQX) {
              res.data.YMQX = [];
            }
            if(!res.data.ROLE_ID) {
              res.data.ROLE_ID = [];
            }
            localStorage.setItem(
              "cst_userInfo",
              JSON.stringify({
                ...res.data,
              })
            );
            let list = initRouter(res.data);
            if(list.length) {
              this.$router.push({
                path: list[0].path
              });
            }else{
              this.$message.error("请联系信息处开通访问权限")
            }
          } else {
            this.$message({
              message: res.msg,
              type: "error",
            });
            // Toast(res.msg);
          }
        })
        .catch((e) => {
          this.loading = false;
      });
    },

    onSubmit() {
      this.$refs["ruleForm"].validate((valid) => {
        if (valid) {

          this.getLogin();
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>

<style lang="less">
.login-html {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  position: relative;
  .yzm {
    .el-form-item__label {
      margin-top: 10px;
    }
  }
  .login-head {
    height: 50px;
    background: #0a5897;
  }
  .header-logo-wrap {
    width: 100%;
    height: 100px;
    .header-inner {
      height: 100%;
      padding: 10px 0 10px 60px;
      span {
        margin: 10px 0;
        display: block;
        padding: 15px 22px;
        border-left: 2px solid #0a5897;
        color: #0a5897;
        font-size: 24px;
        margin-left: 30px;
        font-weight: 550;
        float: left;
      }
      img {
       width: 307px;
        display: block;
        float: left;
      }
    }
  }
  .login-box {
    padding: 20px;
    width: 400px;
    margin: 0 auto;
    position: absolute;
    top: 50%;
    right: 10%;
    margin-top: -220px;
    background: #fff;
    box-shadow: 0px 0px 5px #ccc;
    .logo {
      width: 200px;
      vertical-align: middle;
      display: inline-block;
    }
    .name {
      vertical-align: middle;
      display: inline-block;
      height: 50px;
      line-height: 50px;
      border-left: 2px solid #0a5897;
      color: #0a5897;
      padding-left: 20px;
      margin-left: 20px;
      font-weight: bold;
    }
  }
}
</style>
